#/bin/bash
#auto judge and solve specific jdk download,install and allocation

jdkDir=/usr/local/jdk

#check directory
if [ -e $jdkDir ]
then
	echo "$jdkDir folder exists, operation stop"
	exit
fi

echo "check if there exists jdk 1.8..."
if [ -f $1 ]
then 
	mkdir $jdkDir
	echo "begin decompress..."
	tar -zxvf $1 -C $jdkDir
	for file in $jdkDir
	do
		if [ -d $file ]
		then
			JAVA_HOME=$file
		fi
	done
	echo "JAVA_HOME=$JAVA_HOME"
else
	echo "file not exists :$1"
	exit
fi

#update environment parameter
echo "export JAVA_HOME=$JAVA_HOME" >> /etc/profile
echo "export PATH=\$PATH:\$JAVA_HOME/bin" >> /etc/profile
echo "export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar" >> /etc/profile

echo "jdk install complete..."
echo $(java -version)
